import { Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
import { Menu } from '@/modules/system/menu/entities/menu.entity';
import { RoleApi } from '@/modules/system/role-api/entities/role-api.entity';
import { BaseTimeEntity } from '@/common/entities/base-time.entity';
import { TABLE_PREFIX } from '@/config';


@Entity({ name: `${TABLE_PREFIX}sys_api` })
export class Api extends BaseTimeEntity {
    @PrimaryGeneratedColumn()
    id: number;

    @Column({ type: 'varchar', comment: '接口名称', nullable: false })
    apiName: string;

    @Column({ type: 'varchar', comment: '接口路径', nullable: false })
    apiUrl: string;

    @Column({ type: 'varchar', comment: '请求方式', nullable: false, default: 'GET' })
    method: string;

    @Column({ type: 'int', comment: '菜单id', nullable: false })
    menuId: number;

    @ManyToOne(() => Menu, (menu) => menu.api)
    menu: Menu;

    @OneToMany(() => RoleApi, (roleApi) => roleApi.api)
    roleApi: RoleApi[];
}

